package pl.controller;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class TestController {

	protected final Log log = LogFactory.getLog(getClass());
	
	@RequestMapping("/test/foo.htm")
	public ModelAndView foo(){
		log.debug("przeszlo przez metode foo");
		return new ModelAndView("test/testFoo", "msgFoo", "przeszlo przez metode foo");
	}
	
	@RequestMapping("/test/testFoo.htm")
	public ModelAndView testFoo(){
		log.debug("przeszlo przez metode testFoo");
		return new ModelAndView("test/testFoo", "msgTestFoo", "przeszlo przez metode testFoo");
	}
	
	@RequestMapping("/test/redirToFoo.htm")
	public ModelAndView testRedirToFoo(){
		log.debug("przeszlo przez metode redirToFoo");
		return new ModelAndView("redirect:/test/foo.htm", "msgRedirToFoo", "przeszlo przez metode redirToFoo");
	}
	
	@RequestMapping("/test/forwardToFoo.htm")
	public ModelAndView testForwardToFoo(){
		log.debug("przeszlo przez metode forwardToFoo");
		return new ModelAndView("forward:/test/foo.htm", "msgForwardToFoo", "przeszlo przez metode forwardToFoo");
	}
	
	@RequestMapping("/test/getPdf.htm")
	public ModelAndView testGetPdf(HttpServletRequest request, HttpServletResponse response) throws IOException{
		
		 response.setContentType("application/pdf");  
		 response.addHeader(  
		   "Content-Disposition",  
		   "attachment; filename=PO_testGet.pdf");  
		response.getOutputStream().print("hello world");
		
		return null;
	}
}
